package com.tanhua.houtai.server.controller;


import com.tanhua.houtai.server.domain.ResultInfo;
import com.tanhua.houtai.server.service.impl.PayServer;
import com.tanhua.houtai.server.utils.UuidUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private PayServer payServer;
    @RequestMapping(value = "/getCode",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String createUrl(@RequestBody Map<String, String> params){
        String userId = params.get("userId");
        String s = UuidUtils.simpleUuid();
        String url = payServer.getUrl(s,userId);
        return url;
    }

    @RequestMapping(value = "/checkpay",produces = "application/xml;charset=utf-8")
    @ResponseBody
    public Map<String,String> checkpay(@RequestBody Map<String, String> params){
        ResultInfo resultInfo = payServer.checkPay(params);
        HashMap<String,String> map=new HashMap<>();
        if(resultInfo.getSuccess()){
            map.put("return_code","SUCCESS");
        }else {
            map.put("return_code","FAIL");
        }
        map.put("return_msg","OK");
        return map;
    }
    @RequestMapping(value = "/findstate",produces = "application/json;charset=utf-8")
    @ResponseBody
    public ResultInfo findstate(@RequestBody Map<String, String> params){
        ResultInfo resultInfo = payServer.findstate(params);
        return resultInfo;
    }
}
